package cs236369.hw5.service;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.log4j.Logger;

import cs236369.hw5.db.beans.DbAddress;
import cs236369.hw5.db.beans.DbUser;

public class ServiceManager
{
//	private DbHandler handler;
	private Logger logger = Logger.getLogger(getClass());
	public void registerNewUser(String username, String password, String adminPass, String sirName, String lastName, String country, String city, String street)
	{
		logger.info("register new user " + username);
		String encPass = null;
        try
        {
	        encPass = new String(MessageDigest.getInstance("MD5").digest(password.getBytes("UTF-8")));
	        logger.trace("encoded pass: " + password + ", " + encPass);
        }
        catch (NoSuchAlgorithmException e)
        {
	        logger.error("exception", e);
        }
        catch (UnsupportedEncodingException e)
        {
        	logger.error("exception", e);
        }
		
		DbAddress address = new DbAddress(street, city, country);
		DbUser user = new DbUser(username);
		user.setAddress(address);
		user.setLastName(lastName);
		
		user.setUserpass(encPass);
		
	
		
//		handler.save(user);
	}
}
